﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using VoicePhone.Common;

namespace VoicePhone.Utils
{
    public class CallRollConfig : EntityClassXmlSerializer<CallRollConfig>
    {
        public ObservableCollection<CallRollBase> CallRollBaseList { get; set; } = new ObservableCollection<CallRollBase>();

        public static CallRollConfig Load()
        {
            CallRollConfig CallRollConfig;
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config\\CallRollConfig.xml");
            if (File.Exists(filePath))
            {
                string xmlStr = File.ReadAllText(filePath);
                CallRollConfig = ReadFromXML(xmlStr);
            }
            else
            {
                CallRollConfig = new CallRollConfig();
            }

            return CallRollConfig;
        }

        public void Save()
        {
            this.Save(ToXMLString(this), "CallRollConfig.xml");
        }
    }

    public class CallRollBase : INotifyPropertyChanged
    {
        private int m_Index;
        public int Index
        {
            get { return m_Index; }
            set
            {
                this.m_Index = value;
                this.OnPropertyChanged();
            }
        }

        public string StartTime { get; set; }

        private string m_EndTime;
        public string EndTime
        {
            get { return m_EndTime; }
            set
            {
                this.m_EndTime = value;
                this.OnPropertyChanged();
            }
        }

        public ObservableCollection<CallRoll> CallRollList { get; set; } = new ObservableCollection<CallRoll>();

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged([CallerMemberName]string property = null)
        {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
        }
    }

    public class CallRoll : INotifyPropertyChanged
    {
        public IpPhone Phone { get; set; }

        public string Time { get; set; }

        private string m_Result = "呼叫失败";
        public string Result
        {
            get { return m_Result; }
            set
            {
                this.m_Result = value;
                this.OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged([CallerMemberName]string property = null)
        {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
        }
    }
}